<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>
                    <i class="el-icon-lx-cascades"></i> 登录日志
                </el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div class="handle-box">
                <el-input v-model="query.loginName" placeholder="登录名" class="filter-item handle-input mr10"></el-input>
                <el-button type="primary" icon="el-icon-search" class="filter-item" @click="handleSearch">搜索</el-button>
            </div>
            <el-table
                    v-loading="loading"
                :data="tableData"
                border
                class="table"
                ref="multipleTable"
                header-cell-class-name="table-header"
            >
                <el-table-column type="selection" width="55" align="center"></el-table-column>
                <el-table-column prop="loginName" label="登录名"></el-table-column>
                <el-table-column prop="ipAddress" label="登录地址"></el-table-column>
                <el-table-column prop="browser" label="浏览器"></el-table-column>
                <el-table-column prop="os" label="系统"></el-table-column>
                <el-table-column label="状态" align="center" >
                    <template slot-scope="scope">
                        <el-tag
                            :type="scope.row.status==='0'?'success':(scope.row.status==='1'?'danger':'')"
                        >{{scope.row.status | showStatus}}</el-tag>
                    </template>
                </el-table-column>
                <el-table-column prop="msg" label="提醒"></el-table-column>
                <el-table-column prop="loginTime" label="登录时间" width="180">
                    <template slot-scope="scope">
                        <span>{{ parseDateTime(scope.row.loginTime) }}</span>
                    </template>
                </el-table-column>

            </el-table>
            <div class="pagination">
                <el-pagination
                    background
                    layout="total, prev, pager, next"
                    :current-page="query.current"
                    :page-size="query.size"
                    :total="pageTotal"
                    @current-change="handlePageChange"
                ></el-pagination>
            </div>
        </div>
    </div>
</template>

<script>
import { sysLoginLogPage } from '../../api/sysLoginLog';
import moment from 'moment'

export default {
    name: 'login-log-list',
    data() {
        return {
            // 遮罩层
            loading: true,
            query: {
                loginName: '',
                current: 1,
                size: 10
            },
            tableData: [],
            pageTotal: 0
        };
    },
    created() {
        this.getData();
    },
    methods: {
        getData() {
            this.loading = true;
            sysLoginLogPage(this.query).then(res => {
                this.loading = false;
                this.tableData = res.data;
                this.pageTotal = res.count;
            });
        },
        // 触发搜索按钮
        handleSearch() {
            this.$set(this.query, 'current', 1);
            this.getData();
        },
        // 分页导航
        handlePageChange(val) {
            this.$set(this.query, 'current', val);
            this.getData();
        }
    },
    filters:{
        showStatus(status){
            if (status == "0") {
                return "成功";
            } else if (status == "1") {
                return "失败";
            } else {
                return "";
            }
        }
    }
};
</script>

<style scoped>
.handle-box {
    margin-bottom: 20px;
}
.handle-input {
    width: 300px;
    display: inline-block;
}
.table {
    width: 100%;
    font-size: 14px;
}
.red {
    color: #ff0000;
}
.mr10 {
    margin-right: 10px;
}
.table-td-thumb {
    display: block;
    margin: auto;
    width: 40px;
    height: 40px;
}
</style>
